package nagel_schreckenberg;

public class AverageCar implements Vehicle {
	
	final static int MAXSPEED = 5;
	
	private int id;
	private int speed;
	private int position;
	private boolean moved;
	private int waitingTime;
	private int travelTime;
	
	public enum Heading{
		NORTH, EAST, SOUTH, WEST;
	}
	private Heading heading;
	
	public AverageCar(int id, int sp){
		this.id = id;
		this.speed = sp;
		this.moved = false;
		waitingTime = 0;
		travelTime = 0;
	}
	
	@Override
	public int getID() {
		return id;
	}

	@Override
	public int getSpeed() {
		return speed;
	}
	
	@Override
	public void setSpeed(int d) {
		this.speed = d;
	}
	
	@Override
	public int getMaxSpeed() {
		return MAXSPEED;
	}
	
	@Override
	public void accelerate(int unit) {
		speed+= unit;
	}

	@Override
	public void printVehicle() {
		System.out.println("Vehicle " + this.id + " speed: " + this.speed + " position: " + this.position);	
	}

	@Override
	public int getPosition() {
		return position;
	}

	@Override
	public void setPosition(int pos) {
		this.position = pos;		
	}

	@Override
	public boolean getMoved() {
		return moved;
	}

	@Override
	public void setMoved(boolean m) {
		moved = m;
	}

	@Override
	public boolean isWaiting() {
		boolean wait;
		if(speed == 0){
			wait = true;
		}
		else{
			wait = false;
		}
		return wait;
	}

	@Override
	public int getWaitingTime() {
		return waitingTime;
	}

	@Override
	public void rest() {
		if(speed == 0){
			waitingTime++;
		}	
	}

	@Override
	public int getTravelTime() {
		return travelTime;
	}

	@Override
	public void travel() {
		travelTime++;
	}

	@Override
	public void setHeading(Heading h) {
		heading = h;		
	}

	@Override
	public Heading getHeading() {
		return heading;
	}
}
